package com.dstation.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dstation.dao.DynamicReviewLogInfoMapper;
import com.dstation.domain.DynamicInfo;
import com.dstation.domain.DynamicReviewLogInfo;
import com.dstation.domain.VideoInfo;
import com.dstation.service.interf.IDynamicExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DynamicExamineService implements IDynamicExamineService {

    @Autowired
    DynamicReviewLogInfoMapper dynamicReviewLogInfoMapper;
    @Override
    public IPage<DynamicInfo> findAllNotAccessDynamicInfo(Page<VideoInfo> videoInfoPage) {
        int i = 0;
        DynamicInfo dynamicInfo = null;
        IPage<DynamicInfo> dynamicInfoIPage = dynamicReviewLogInfoMapper.selectAllNotAccessDynamicInfo(videoInfoPage);
        JSONObject json = null;
        for(i = 0; i < dynamicInfoIPage.getRecords().size(); i ++) {
            dynamicInfo = dynamicInfoIPage.getRecords().get(i);
            json = JSONObject.parseObject(dynamicInfo.getDynamicContent());
            dynamicInfo.setDynamicContent(json.getString("dynamicContent"));
        }
        return dynamicInfoIPage;
    }

    @Override
    public boolean alterDynamicStatusByVideoId(long dynamicId, boolean isPass) {
        return dynamicReviewLogInfoMapper.alterDynamicStatusByVideoId(dynamicId, isPass);
    }

    @Override
    public boolean addDynamicReviewLogInfo(DynamicReviewLogInfo dynamicReviewLogInfo) {
        return dynamicReviewLogInfoMapper.insertDynamicReviewLogInfo(dynamicReviewLogInfo);
    }

    @Override
    public DynamicInfo findDynamicInfoByDynamicID(long dynamicId) {
        return dynamicReviewLogInfoMapper.selectDynamicInfoByDynamicID(dynamicId);
    }
}
